package com.onlinemovies.service.implementation;

import java.io.Serializable;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.onlinemovies.entity.User;
import com.onlinemovies.repository.extension.UserRepository;
import com.onlinemovies.service.UserService;



@Service("userService")
@Transactional(readOnly=true)
public class UserServiceImpl implements UserService,Serializable{

	@Autowired
	private UserRepository userRepository;
	
	@Override
	public List<User> getAll() throws Exception {
		List<User> alluser = userRepository.getAll();
		return alluser;
	}


	@Override
	@Transactional(readOnly=false)
	public User doRegistration(User user) throws Exception {
		return userRepository.merge(user);
	}


	@Override
	public boolean doLogIn(User user,HttpSession httpSession) {
		boolean flag=userRepository.doLogIn(user,httpSession);
		return flag;
	}


	@Override
	public void dologout(HttpSession httpSession) {
		httpSession.removeAttribute("user");
	}

}
